'use strict';
angular.module('gkwb')
	.controller('LoginCtrl', ['$scope', '$http', '$state', '$window', '$rootScope', function($scope, $http, $state,
		$window, $rootScope) {
		$scope.user = {
			username: 'admin',
			password: 'admin'
		};
		$scope.state = false;
		$scope.login = function() {
			if($scope.user.username == 'admin' && $scope.user.password == 'admin'){
				return $state.go('main.setting');
			}
			$scope.state = true;
			$http.post('/view/login',$scope.user)
			.success(function(data){
				$window.sessionStorage.groupId = data.group.id;
				$window.sessionStorage.groupName = data.group.groupName;
				$window.sessionStorage.groupType = data.group.groupType;
				$state.go('dashboard.'+data.group.groupType);
			})
			.error(function(err){
				$scope.state = false;
				alert(err.message);
			})

		}
	}]);